<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/inc/common.jsp"%>
<jsp:include page="/business/shuttle/query.jsp"/>
<html>
<head>
<title>终检亭入境放行卡</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<script type="text/javascript">
	$(function() {
		initDg();//初始化datagrid
	});
	
	//回车查询
	$(document).keydown(function(e){
		if(e.keyCode == 13) {
			searchDate();
		}
	});
	
	//初始化数据列表
	function initDg(){
		$('#dg').datagrid({
			url:'${basePath}/bus/enterCard/query.do',
			queryParams:{entryExitType:"101101"},
			loadMsg:'数据装载中......',
		    title:'结果列表',//标题
		    width:'auto',//列表的宽度
			height:'auto',//列表的高度
			fit:true,//自动填充全屏
			nowrap: false,//数据是否显示在一行中
			fitColumns:true,//是否根据字体数收缩
		    pagination:true,//分页底部显示
		    pageList:[10,20,50],//设置分页下拉页数
		    rownumbers : true,//显示行号
			//singleSelect:true,//只能单选
			autoRowHeight:false,//自动行高
			idField : 'id',
		    columns:[[
				{field:'ck',checkbox:'true'},
				{field:'CAR_NO',title:'车牌号',width:fixWidth(10),align:'center',
					formatter:function(value,row,index){
		                return formatBlackImage(value,row,index);
		            }
				},
				{field:'SERIAL_NO',title:'流水号',width:fixWidth(15),align:'center'},
				{field:'CHINESE_NUM',title:'中国旅客人数',width:fixWidth(10),align:'center'},
				{field:'FOREIGN_NUM',title:'外国旅客人数',width:fixWidth(10),align:'center'},
				{field:'TOTAL_NUM',title:'总人数',width:fixWidth(5),align:'center'},
				{field:'NATIONALITY',title:'国籍',width:fixWidth(10),align:'center',
					formatter:function(value,row,index){
		                return parent.formartDic(value,"1005");
		            }	
				},
				{field:'ENTRY_TIME',title:'入境时间',width:fixWidth(15),align:'center',
					formatter:function(value,row,index){
						return changeDateTimeToString(value);
					}	
				},
				{field:'CAR_TYPE',title:'车辆类型',width:fixWidth(10),align:'center',
					formatter:function(value,row,index){
		                return parent.formartDic(value,"1009");
		            }	
				},
				{field:'IS_PROCESS',title:'是否已处理',width:fixWidth(10),align:'center',
					formatter:function(value,row,index){
		                return parent.formartDic(value,"1013");
		            }
				},
			]],
			toolbar:[
					{
							id : 'dg-add',
							text : '新增',
							iconCls : 'icon-add',
							handler : function() {
								editData();
							}
						},'-',{
							id : 'dg-edit',
							text : '修改',
							iconCls : 'icon-edit',
							handler : function() {
								var row = $('#dg').datagrid('getSelected');
								if (row) {
									if(row.isProcess == '101301'){
										$.messager.alert('消息', "该车辆已处理完成，无法进行修改!",'info');	
									}else{
										editData(row.id);
									}
								}else{
									$.messager.alert('消息', "请选择一条信息!",'info');	
								}
							}
						},'-',{
							id : 'dg-edit',
							text : '查看',
							iconCls : 'icon-application_form_magnify',
							handler : function() {
								var row = $('#dg').datagrid('getSelected');
								if (row) {
									lookData(row.id);
								}else{
									$.messager.alert('消息', "请选择一条信息!",'info');	
								}
						}
						},'-',{
							id : 'dg-error',
							text : '退车',
							iconCls : 'icon-error_delete',
							handler : function() {
								var row = $('#dg').datagrid('getSelected');
								if (row){
									if(row.isProcess == '101302'){
										$.messager.confirm('系统提示', '您确定要进行退车吗?', function(r) {
											if(r){
												showWindow(row.id);
											}
										});
									}else if(row.isProcess == '101301'){
										$.messager.alert('消息', "该车辆已处理!",'info');	
									}else if(row.isProcess == '101303'){
										$.messager.alert('消息', "该车辆已经被退车!",'info');	
									}
								}else{
					   				$.messager.alert('消息', "请选择一条信息!",'info');	
					   			}
							}
						},'-',{
							id : 'dg-car-add',
							text : '班车',
							iconCls : 'icon-car_add',
							handler : function() {
								busShowWindow();
							}
						},'-',{
							id : 'dg-print',
							text : '导出',
							iconCls : 'icon-redo',
							handler : function() {
								//获取查询参数和分页参数
								var params = $('#dg').datagrid('options').queryParams; //先取得 datagrid 的查询参数
						        var fields =$('#searchForm').serializeArray(); //自动序列化表单元素为JSON对象  
						        $.each( fields, function(i, field){
						            params[field.name] = field.value; //设置查询参数  
						        });
						        var pagination = $('#dg').datagrid('getPager').data("pagination").options;  
						        var data=JSON.stringify(params);
						        var pdata=JSON.stringify(pagination);
						        
								location.href = path+"/bus/enterCard/exportXls.do?data="+data+"&pdata="+pdata;
							}
						}
				   	],
            onSelect: function (index, row) {
            	//setDgBut(1,1);//设置单选的按钮状态
            },
            onUnselect: function (index, row) {
            	//setDgBut(2,1);//设置取消单选的按钮状态
            },
            onSelectAll: function (index, row) {
            	setDgBut(3,index.length);//设置全选的按钮状态
            },
            onUnselectAll: function (index, row) {
            	setDgBut(2,index.length);//设置取消全选的按钮状态
            },
            onLoadSuccess:function(){
            	onLoadSuccess();
			}
		});
	}
	//查看
	function lookData(id){
		if(id != null && id != "undefined" && id != ""){
			window.location.href="${basePath}/bus/enterCard/view.do?id="+id;
		}
	}
	//清空
	function cleanDate(){
		$('#searchForm').form('clear');
	}
	//查询
	function searchDate(){
		var params = $('#dg').datagrid('options').queryParams; //先取得 datagrid 的查询参数
        var fields =$('#searchForm').serializeArray(); //自动序列化表单元素为JSON对象  
        $.each( fields, function(i, field){
            params[field.name] = field.value; //设置查询参数  
        });
        $('#dg').datagrid('reload'); //设置好查询参数 reload 一下就可以了 
	}
	//编辑
	function editData(id){
		if(id != null && id != "undefined" && id != ""){
			window.location.href="${basePath}/bus/enterCard/edit.do?id="+id;
		}else{
			window.location.href="${basePath}/bus/enterCard/edit.do";
		}
	}
	
	
	//删除
	function deleteData(row){
		var ids = "";
		for(var i=0;i<row.length;i++){
			ids = ids+","+row[i].id;
		}
		if(ids!="" && ids.length>0){
			ids = ids.substring(1, ids.length);
			$.ajax({
	            url:'${basePath}/bus/enterCard/delete.do',  
	            type:'post',         
	            data:"ids="+ids, 
	            dataType:"json",
	            success:function(msg){
	            	$.each(msg,function(i,n){
	            		if(n.message == "success"){
	            			$('#dg').datagrid('reload');
	            		}else{
	            			$.messager.alert('消息', "失败!请重新操作!");
	            		}
	               });
	                 
	           	}
	         });
		}
	}
	
	//显示弹出窗体  班车信息
	function busShowWindow(){
		var carNo = $("#carNo").textbox('getValue');
		$("#sw").panel({title:'班车信息'});
		$('#sTable').datagrid('clearSelections');//清除选中行
		initsq("${basePath}/bus/shuttle/query.do?carNo="+carNo);
		$('#sw').window('open');
	}
	
	//显示弹出窗体
	function showWindow(id){
		$("#selectId").val(id);
		$("#ew").panel({title:'退车'});
		$('#ew').window('open');
	}
	
	//退车
	function returnDate(){
		var selectId = $("#selectId").val();
		var backCarReason = $("#backCarReason").textbox('getValue');
		var backRemark = $("#backRemark").textbox('getValue');
		$.ajax({
            url:'${basePath}/bus/enterCard/returnCar.do',  
            type:'post',
            data:"id="+selectId+"&backCarReason="+backCarReason+"&backRemark="+backRemark+"&type=1", 
            dataType:"json",
            success:function(msg){
            	$.each(msg,function(i,n){
            		if(n.message == "success"){
            			$.messager.alert('消息', "操作成功!");
            			closeWindow();
            			$('#dg').datagrid('reload');
            		}else{
            			$.messager.alert('消息', "失败!请重新操作!");
            		}
               });
                 
           	}
         });
	}
</script>
<body>
	<div class="easyui-layout" fit="true">
			<div id="p" class="easyui-panel"  data-options="region:'north',split:true,hideCollapsedContent:false,footer:'#searchfooter'" title="查询条件" style="overflow: hidden;">
			<!-- 查询条件 -->
			<div style="padding:10px 5px 45px 20px;">
			<form id="searchForm" name="searchForm" style="margin-bottom: 0px;">
					<table class="search-table"  width="90%" cellpadding="0" cellspacing="0" border="0">
						<tr>
							<td align="right" width="15%">车牌号:</td>
							<td>
								<input class="easyui-textbox" type="text" id="carNo" name="carNo"></input>
							</td>
							<td align="right" width="15%">是否处理:</td>
							<td>
								<input class="easyui-combobox" type="text" id="isProcess" name="isProcess" data-options="url:'${basePath}/sys/dictionary/dicbykey.do?key=1013&type=1',method:'get',valueField:'dataCode',textField:'dataName',panelHeight:'auto',editable:false"></input>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<!-- 搜索按钮 -->
			<div id="searchfooter" style="text-align:right;padding: 0px 10px">
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="searchDate()"  data-options="iconCls:'icon-search',plain:true" >查询</a>
				<span class="search-btn-separator"></span>
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="cleanDate()" data-options="iconCls:'icon-cross',plain:true">重置</a>
			</div>
		</div>
		<!-- 数据列表 -->
		<div region="center" split="true" border="false" style="overflow: hidden;width: 99%;height: auto">
			<table id="dg"></table>
		</div>
	</div>
	
	<!--退车--弹出对话框 -->
	<div id="ew" class="easyui-window" style="width:400px;height:400px;padding:5px; background: #fafafa;" 
		data-options="modal:true,closed:true,iconCls:'icon-save',footer:'#dialogfooter'">
		<div class="easyui-layout" fit="true">
			<div region="center" border="false"
				style="padding: 5px;10px;10px;10px; background: #fff; border: 1px solid #ccc;">
				<table  style="width:100%;" cellpadding="0" cellspacing="1"  class="formtable">
			    	<tr>
				    	<td align="right" style="width: 30%">退车原因:</td>
						<td class="value">
							<input type="hidden" id="selectId" name="selectId">
							<input class="easyui-textbox" type="text" id="backCarReason" name="backCarReason" style="width: 250px;">
						</td>
					</tr>
					<tr>
				    	<td align="right" style="width: 30%">退车备注:</td>
						<td class="value">
							<input class="easyui-textbox" data-options="multiline:true" style="width: 250px;height:100px" type="text" name="backRemark" id="backRemark">
						</td>
					</tr>
			    	</table>
			    </form>
			</div>
			<div id="dialogfooter" style="text-align:right;padding: 0px 10px">
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="returnDate()"  data-options="iconCls:'icon-page_save',plain:true" >保存</a>
				<span class="search-btn-separator"></span>
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeWindow()" data-options="iconCls:'icon-cross',plain:true">返回</a>
			</div>
		</div>
	</div>
</body>
</html>
